{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "eddb0e02",
   "metadata": {},
   "source": [
    "# 1.textblob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "38b5312f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: textblob in c:\\users\\pc\\anaconda3\\lib\\site-packages (0.18.0.post0)\n",
      "Requirement already satisfied: nltk>=3.8 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from textblob) (3.8.1)\n",
      "Requirement already satisfied: tqdm in c:\\users\\pc\\anaconda3\\lib\\site-packages (from nltk>=3.8->textblob) (4.59.0)\n",
      "Requirement already satisfied: regex>=2021.8.3 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from nltk>=3.8->textblob) (2024.5.15)\n",
      "Requirement already satisfied: joblib in c:\\users\\pc\\anaconda3\\lib\\site-packages (from nltk>=3.8->textblob) (1.0.1)\n",
      "Requirement already satisfied: click in c:\\users\\pc\\anaconda3\\lib\\site-packages (from nltk>=3.8->textblob) (7.1.2)\n"
     ]
    }
   ],
   "source": [
    "! pip install textblob"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64934e6b",
   "metadata": {},
   "source": [
    "* textblob是一个第三方的情感分析库，使用前要先下载\n",
    "* 情感得分是介于-1-1之间，正数表示积极情感，负数表示消极，0表示中立\n",
    "* 不适应于中文和长文本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5b15f3c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "情感得分:0.75\n"
     ]
    }
   ],
   "source": [
    "from textblob import TextBlob\n",
    "\n",
    "text = \"this product is very great , i am satisfied\"\n",
    "\n",
    "blob = TextBlob(text) # 创建情感得分对象\n",
    "\n",
    "score = blob.sentiment.polarity #调用api方法，计算情感得分\n",
    "\n",
    "print(f\"情感得分:{score}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc731583",
   "metadata": {},
   "source": [
    "# 2.vader"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5421f3ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting vaderSentiment\n",
      "  Downloading vaderSentiment-3.3.2-py2.py3-none-any.whl (125 kB)\n",
      "Requirement already satisfied: requests in c:\\users\\pc\\anaconda3\\lib\\site-packages (from vaderSentiment) (2.25.1)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from requests->vaderSentiment) (2020.12.5)\n",
      "Requirement already satisfied: chardet<5,>=3.0.2 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from requests->vaderSentiment) (4.0.0)\n",
      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from requests->vaderSentiment) (1.26.4)\n",
      "Requirement already satisfied: idna<3,>=2.5 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from requests->vaderSentiment) (2.10)\n",
      "Installing collected packages: vaderSentiment\n",
      "Successfully installed vaderSentiment-3.3.2\n"
     ]
    }
   ],
   "source": [
    "! pip install vaderSentiment"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b7ec9d8",
   "metadata": {},
   "source": [
    "* 计算更加精细，可以计算各维度消息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7810f213",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "情感得分:{'neg': 0.0, 'neu': 0.714, 'pos': 0.286, 'compound': 0.4215}\n"
     ]
    }
   ],
   "source": [
    "from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer\n",
    "\n",
    "text = \"this product is grest , i am satisfied\"\n",
    "\n",
    "analyzer = SentimentIntensityAnalyzer()\n",
    "\n",
    "scores = analyzer.polarity_scores(text)\n",
    "\n",
    "print(f\"情感得分:{scores}\")\n",
    "\n",
    "# 消极，中立，积极，加权分数                         "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f285306",
   "metadata": {},
   "source": [
    "# 3.snownlp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6fb34774",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting snownlp\n",
      "  Downloading snownlp-0.12.3.tar.gz (37.6 MB)\n",
      "Building wheels for collected packages: snownlp\n",
      "  Building wheel for snownlp (setup.py): started\n",
      "  Building wheel for snownlp (setup.py): finished with status 'done'\n",
      "  Created wheel for snownlp: filename=snownlp-0.12.3-py3-none-any.whl size=37760957 sha256=70c6d0c42c6379fdb84f85953b3864a25a5502aa6f98d5b6bb334bada3aaf94e\n",
      "  Stored in directory: c:\\users\\pc\\appdata\\local\\pip\\cache\\wheels\\09\\14\\c5\\ea9aee34229caa97c6f6ff78c82c7f2b1a3423c1f37227b6a6\n",
      "Successfully built snownlp\n",
      "Installing collected packages: snownlp\n",
      "Successfully installed snownlp-0.12.3\n"
     ]
    }
   ],
   "source": [
    "! pip install snownlp"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54e442fc",
   "metadata": {},
   "source": [
    "* sentiments>0.6可以判定为积极情感，0.6<sentiments<=0.6可以判定为中性情感，<=0.4可以判定为消极情感"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4ce7ed95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "情感得分:0.9528403212056912\n"
     ]
    }
   ],
   "source": [
    "from snownlp import SnowNLP\n",
    "\n",
    "text = \"这个产品太棒了，我非常满意\"\n",
    "\n",
    "nlp = SnowNLP(text)\n",
    "\n",
    "score = nlp.sentiments\n",
    "\n",
    "print(f\"情感得分:{score}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a668e026",
   "metadata": {},
   "source": [
    "# 4.分析结果可视化matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15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ucEl/UkBV1UMD167xuAS4pKoeTPJYun79G4Hzq+q8fj/xEF034VGs335kIjx1cW470k1S9/a1bZRkKV3z/z3AgiTvSfLLA9SngVTVF+mmLL8E+BBwTj+49zW6L/dX6c7+uCzJpUkupTtDZA+6LqHP0Z1B9PTBi9dY9Gd+JcnvAJ+iOwh8NXBkktOBqT7s12s/Mkm2AOb2eOAlVXVnn9afTlJ0ZwAlyVPpTvf7v8CJVfXPdCsOAU5N8mS6QT9P/dsy/AVwH7AC+HaSPYB9gJ8C+/Wn/85Makj/+Tiuqo6bQK0asySL6I76vwocXlV39Kv+Yx8KK/vTgte6H5lA6Q/jIPA6JFlYVffPWhZg26q6d32fo81Tf6HfmcC36Pr+fxk4Dfhj4Ad01wO8pKpu6Ld/HvBaYNVMl5C0qe4TDABpHZLMH7noL8BWIxeAZfSsn75PeBfgG/b5a1NnAEhSoxwElqRGGQCS1CgDQFqLJAuTLEvyh0k+mWR5kq37df8jyXP6+y9N8s0kn511+1Z/pai0yfE0UGnttqGbzvdA4DVVdU2Sdyf5HN08PzMzvt4PrKyqd4w+OcmfjGwjbVIMAGntfkR3QddfAPf0V/W+Cfgk3eRwMx4Cjkly+KznLwHeMECd0iNmAEhrdxDw3+jO/98X+Gu6nf2zgbfN2nZNLQBpk+QYgLQWVfU54DfpDpY+3992pWsRSJs1WwDSuh0P3AacRzf3/6nA7wJHAvv0k79NYxeQNjMGgLQWSfYDnkF35H8b3Vzu7wWuousKem9VXZDkBdgFpM2MASCt3e3Af6KbCI6qmpnnnSSn0g0SQze515paACcMUKf0iBkA0lpU1c3QXQ8ALJi1egHdTwFC9106o6reNbpB3wLwe6ZNknMBSVKjPAtIkhplAEhSowwASWqUASBJjTIAJKlR/x8VbbdZCFdobAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "\n",
    "x = [\"语文\",\"数学\",\"英语\"]\n",
    "y = [99,99,95]\n",
    "# 使用柱形图，输出学生的各科分数\n",
    "\n",
    "plt.bar(x,y,width=0.3,color=[\"red\",\"yellow\",\"pink\"])\n",
    "# 定义颜色和主题的宽度\n",
    "\n",
    "plt.xlabel(\"科目\")\n",
    "plt.ylabel(\"分数\")\n",
    "plt.title(\"张三的成绩\")\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d101d8e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
